﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using HeThongDoDien.IO;

namespace HeThongDoDien
{
    static class Program
    {
        static RSC232Connector connector;
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            //connector = TestCOMConnection();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmMain());
            //connector.Close();
        }

        private static RSC232Connector TestCOMConnection()
        {
            var rsc232 = new RSC232Connector();
            rsc232.DataIncoming += new DataIncomingHandler(rsc232_DataIncoming);
            rsc232.LogMsg += new LogMsgHandler(rsc232_LogMsg);
            rsc232.PortName = "COM11";
            rsc232.Open();
            return rsc232;
        }

        static void rsc232_LogMsg(object sender, LogMsgTypeEnum type, string message)
        {
            Console.WriteLine(message);
        }

        static void rsc232_DataIncoming(object sender, byte[] data)
        {
            var text = System.Text.Encoding.UTF8.GetString(data);
            Console.WriteLine(text);
        }
    }
}
